using System.Threading;
using System.Threading.Tasks;
using MediatR;
using B.S.BasicData.EroorCode;
using B.S.BasicData.Domain;
using B.S.BasicData.Infrature;

public class BreedingEnterpriseInfoGetByIdHandler : IRequestHandler<BreedingEnterpriseInfoGetByIdRequest, ApiResult<BreedingEnterpriseInfo>>
{
    private readonly IBaseRepository<BreedingEnterpriseInfo> _repository;

    public BreedingEnterpriseInfoGetByIdHandler(IBaseRepository<BreedingEnterpriseInfo> repository)
    {
        _repository = repository;
    }

    public async Task<ApiResult<BreedingEnterpriseInfo>> Handle(BreedingEnterpriseInfoGetByIdRequest request, CancellationToken cancellationToken)
    {
        var entity = await _repository.GetByIdAsync(request.Id);
        if (entity == null)
            return ApiResult<BreedingEnterpriseInfo>.Fail("未找到对应的养殖企业信息");
        return ApiResult<BreedingEnterpriseInfo>.Success(entity, "查询成功");
    }
} 